import $ from '../common';
Page({
  data: {
    // 相关功能的数组
    aboutArr: [{
        item: [{
          img: '../../image/icon_kebiao.png',
          tile: '校园选课',
          id: 1
        }, {
          img: '../../image/icon_dianming.png',
          tile: '校外课程',
          id: 2
        }, {
          img: '../../image/icon_dianping.png',
          tile: '校外机构',
          id: 3
        }, {
          img: '../../image/icon_zuoye.png',
          tile: '社会实践',
          id: 4
        }]
      },
      {
        item: [{
          img: '../../image/icon_banji.png',
          tile: '考级考段',
          id: 5
        }, {
          img: '../../image/icon_fankui.png',
          tile: '名师在线',
          id: 6
        }, {
          img: '../../image/icon_qiandao.png',
          tile: '学习培训',
          id: 7
        }, {
          img: '../../image/icon_qiandao.png',
          tile: '赛事',
          id: 8
        }]
      }
    ],
    hotarr: [], // 热门赛事  
    studyarr: [], //在线学习的数组
    campusarr: [], //机构
    teacherarr: [],
    current: 0,
  },
  openabout(e) {
    const {
      currentTarget: {
        dataset: {
          id
        }
      }
    } = e;
    switch (id) {
      case 1:
        break;
      case 2:
        break;
      case 3:
        break;
      case 4:
        this.gosocial()
        break;
      case 5:
        this.gograding()
        break;
      case 6:
        break;
      case 7:
        this.gostudy()
        break;
      case 8:
        this.goeventlist()
        break;
    }
  },
  // 分享
  onShareAppMessage(res) {
    return {
      title: '课袋管家教师端',
      path: '/pages/index/index',
      imageUrl: 'https://sxzimgs.oss-cn-shanghai.aliyuncs.com/yingxiao/page/857f611a-d115-11ec-a9ca-00163e04cc20.jpeg'
    }
  },


  //去往在线学习
  goonlinelearn() {
    $.navigateTo('/learn/onlinelearn')
  },
  // 去往赛事详情
  goevent(e) {
    const {
      uuid = ''
    } = e.currentTarget.dataset
    $.navigateTo(`/match/matchdetail?uuid=${uuid}&name=赛事&type=4`)
  },
  // 去往赛事列表
  goeventlist() {
    $.navigateTo('/match/matchlist?type=4&name=热门赛事')
  },
  //去往课程
  goclass(e) {
    const {
      uuid
    } = e.currentTarget.dataset
    $.navigateTo(`/course/coursedetails?uuid=${uuid}`)
  },
  // 相关功能
  gostudy() { //去往校外机构
    $.navigateTo('/match/matchlist?type=3&name=学习培训')
  },
  gosocial() { //去往校外机构
    $.navigateTo('/match/matchlist?type=1&name=社会实践')
  },
  gograding() { //去往考级考段
    $.navigateTo('/match/matchlist?type=2&name=考级考段')
  },
  //swiper 变化事件
  monitorCurrent(e) {
    let current = e.detail.current;
    this.setData({
      current: current
    })
  },
  gochooseaddress() { //选择地址
    $.navigateTo('/address/chooseaddress')
  },
  //获取banner
  getbanner() {
    $.get('/banner/show', {
      zonecode: this.data.addresscode,
      btype: 'APP_HOME_TOP'
    }, res => {
      this.setData({
        banner: res
      })
    })
  },
  //暂定热门赛事
  getonlinestudy() {
    $.get('/vcourse/hot', {
      zonecode: this.data.addresscode,
      limit: 4,
      page: 1
    }, res => {
      this.setData({
        studyarr: res.vcourses
      })
    })
  },
  //暂定老师
  getteacher() {
    $.get('/campus/teacher', {
      zonecode: this.data.addresscode,
      campus_category: 'INSTITUTION',
      recommend: 'YES'
    }, res => {
      this.setData({
        teacherarr: res.teachers
      })
    })
  },
  //暂定
  getcampus() {
    $.get('/campus/course', {
      zonecode: this.data.addresscode,
      campus_uuid: '',
      category: '',
      limit: '',
      name: '',
      page: '',
      recommend: 'YES'
    }, res => {})
  },
  //暂定 赛事
  getcompetition() {
    $.get('/competition/list', {
      limit: 10,
      name: '',
      page: 1
    }, res => {
      this.setData({
        hotarr: res.competition
      })
    })
  },
  //暂定机构
  getinstitution() {
    $.get('/campus/institution/query', {
      zonecode: this.data.addresscode,
      latitude: 30.276227,
      limit: '',
      longitude: 119.992918,
      name: '',
      page: '',
      recommend: 'YES'
    }, res => {
      this.setData({
        campusarr: res.institution
      })
    })
  },
  onLoad(e) {
    wx.removeStorageSync('$alreadyLoginWindow')
    this.setData({
      address: wx.getStorageSync('address') || '',
      addresscode: wx.getStorageSync('addresscode') || ''
    })

  },
  onShow() {
    this.getbanner()
    this.getonlinestudy()
    this.getcampus()
    this.getcompetition()
    this.getinstitution()
    this.getteacher()
  }
})